﻿using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace BGShell.Controls
{
    [System.ComponentModel.DesignerCategory("Code")]
    internal class AeroGreenBluePanel : Panel
    {
        private static readonly Color ColorA = Color.FromArgb(82, 134, 161);
        private static readonly Color ColorB = Color.FromArgb(82, 159, 87);

        private Orientation _orientation;

        public AeroGreenBluePanel()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.StandardClick, false);
            SetStyle(ControlStyles.StandardDoubleClick, false);
            SetStyle(ControlStyles.SupportsTransparentBackColor, false);
            SetStyle(ControlStyles.UserMouse, false);
            SetStyle(ControlStyles.UserPaint, true);
        }

        public Orientation Orientation
        {
            get { return _orientation; }
            set
            {
                if (_orientation != value)
                {
                    _orientation = value;
                    Invalidate();
                }
            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            using (var brush = CreateBrush())
            {
                e.Graphics.FillRectangle(brush, ClientRectangle);
            }
        }

        private Brush CreateBrush()
        {
            if (_orientation == Orientation.Horizontal)
            {
                return new LinearGradientBrush(ClientRectangle, ColorA, ColorB, 0, false);
            }

            return new LinearGradientBrush(ClientRectangle, ColorA, ColorB, -90, false);
        }
    }
}
